<template>
    <my-ref
        v-if="table"
        url="/dev/api-define/list"
        v-model="table"
        @loaded="procData"
        :multi="$props.multi"
        :page-size="10"
        ref="list"
        name="Api定义"
        :store="true"
        v-bind="$attrs"
        row-key="id"
        @change="v=>$emit('change',v)"
        :readOnly="$props.readOnly"
    >
        <el-table-column align="center" label="产品线" >
            <template v-slot="scope">
                <el-tag v-if="scope.row.productLine">{{ scope.row.productLine.name }}</el-tag>
            </template>
        </el-table-column>
        <el-table-column align="center" label="模块" prop="group"></el-table-column>

        <el-table-column label="名称" align="center">
            <template v-slot="scope">
                {{ scope.row.name }}
            </template>
        </el-table-column>
        <el-table-column align="center" label="地址" prop="url"></el-table-column>
        <el-table-column align="center" label="HTTP方法" prop="httpMethod"></el-table-column>
        <el-table-column align="center" label="header" prop="header"></el-table-column>
        <el-table-column align="center" label="请求Body" prop="body"></el-table-column>
        <el-table-column align="center" label="备注" prop="remark"></el-table-column>
        <template #query="scope">
            <kv label="产品线">
                <product-line v-model="scope.query.productLineCode"></product-line>
            </kv>
            <kv label="模块"> <el-input v-model="scope.query.group"></el-input> </kv>
            <kv label="关键字"> <el-input v-model="scope.query.text"></el-input> </kv>
        </template>
        <template #button>
            <el-button>选择Api</el-button>
        </template>
    </my-ref>
</template>
<script setup>
/**
 * Created by CodeGenerator at 2023-10-03 20:42:08
 */

import productLine from "@/component/product-line.vue";



defineOptions({
    name: "ref-api-define",
    inheritAttrs: true,
});

//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();

const $props = defineProps({
    readOnly : { type: Boolean },
    multi : { type: Boolean }
});


const $model = defineModel({ type: [Object,Array] });

const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","change"]);

const table = $computed({ get() {
        return $model.value;
    },set(v){
        var v = Object.assign(v.getJsType() == "array" ? [] : {}, v);
        $emit("update:modelValue", v);
    } });

const procData = function(res, op) {
    let json = res.data.data;
    json.forEach(it => {
//如果是组合实体，设置 it.id=...
        jv.enum.HttpMethod.fillRes(it, "httpMethod");
    });
};
</script>